package dnl.persistence.orm;

/**
 * 
 * @author Daniel Orr
 *
 */
public class WhereBlock extends QueryBlock {

	private boolean preAppendAnd = true;
	
	public WhereBlock() {
		super("where");
	}

	public void and(String s) {
		String app = "and ";
		if(!preAppendAnd){
			app = "";
		}
		append(s, app);
		preAppendAnd = true;
	}

	/**
	 * 
	 */
	public void and(){
		super.append("and");
	}

	public void or(String s) {
		
		append(s, "or");
	}

	public void or(){
		super.append("or");
	}
	
	public void openParenthesesInWhereBlock(){
		super.append("(");
		increaseIndent();
		preAppendAnd = false;
	}

	public void closeParenthesesInWhereBlock(){
		decreaseIndent();
		super.append(")");
	}
	
	@Override
	public void append(String s){
		if(!isEmpty() && preAppendAnd){
			and(s);
		}
		else {
			super.append(s);
		}
	}

}
